using System;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Domain.Services;
using Domain.Entities;
using Domain.Misc;
using System.Collections.Generic;
using UserInterface.Misc;

namespace UserInterface
{
    public partial class ActiveTopics : BoardPageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int activeHours = 24;
                DateTime activeDateTime = DateTime.Now.Subtract(TimeSpan.FromHours(activeHours));

                IList<Topic> topics = TopicService.GetTopicsWithPostsNewerThanOrAt(activeDateTime);
                TopicRepeater.DataSource = PermissionManager.FilterReadableTopics(topics);
                TopicRepeater.DataBind();

                string pageTitle = (string)GetLocalResourceObject("Title");

                MasterPage.TitleGenerator.PageTitle = pageTitle;
                MasterPage.HeaderText = pageTitle;
                MasterPage.AddPathItem(pageTitle, "ActiveTopics.aspx");
            }
        }

        protected void TopicRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Topic topic = e.Item.DataItem as Topic;
                Image topicTypeImage = e.Item.FindControl("TopicTypeImage") as Image;
                topicTypeImage.ImageUrl = UITools.GetTopicTypeImageUrl(topic);
            }
        }
    }
}
